﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Raven.Client;
using BattleThis.Core;

namespace BattleThis.RavenDB
{
	/// <summary>
	/// Represent a RavenDB Session. Inside the session we make your querys.
	/// </summary>
	public class RavenUnitOfWork : IUnitOfWork
	{
		public IDocumentSession Session { get; private set; }

        public RavenUnitOfWork( IDocumentStore store )
        {
			if( store == null ) throw new ArgumentNullException( "store" );

            this.Session = store.OpenSession();
        }

        #region IUnitOfWork Members

        public void Commit()
        {
            this.Session.SaveChanges();
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            if (this.Session != null)
            {
                this.Session.Dispose();
                this.Session = null;
            }

            GC.SuppressFinalize(this);
        }

        #endregion
	}
}
